Provision Haproxy on AWS using Ansible
Hi there! Today we are going to see how we can configure haproxy and webserver setup on EC2 instances. So let's get into it. I have already discussed briefly what is a load balancer and stuff. You can see it here.
Let's start
So we will have a setup like this :
- 2 Webservers with tag [ env: Webserver ]
- 1 Load Balancer with tag [ env: Loadbalancer ]
Our playbook looks like this.
You can see it here
I have also used different variable files to provide the required values to launch and configure the instance.
And I have used VAULT here to store my AWS credentials in an encrypted form so that it can't be accessed by anyone directly. You can see it here.
So now let's run our playbook using ansible-playbook --ask-vault-pass main.yml
. Here --ask-vault-pass will ask the password to decrypt the vault and use those credentials in the playbook.
You can see our playbook ran successfully and now let's check AWS console.
You can see it is configured and now let's see the results.
Yes, we can access the servers and load-balancing is happening too. So in this way, we can setup simple load balancer on AWS EC2 instance.
That's it for this one and see you again next time ....!!